﻿using AutoDeployForSims.Model.Get10AnalogEnt;
using AutoDeployForSims.Utility;
using MyUtility.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows;

namespace AutoDeployForSims.Service
{
    public class GetInit10Config
    {
        //转换顺序表
        private string[] childTypes = { "全体模拟量", "电缆绝缘", "电源漏流", "道岔启动电流", "拉力", "油压", "高压不对称电压波形", "外电网瞬间断电曲线" };
        //analog子项对应关系表
        private Dictionary<string, string> analogChildMap = new Dictionary<string, string>();
        public Dictionary<string, string> AnalogChildMap
        {
            get { return analogChildMap; }
            set { analogChildMap = value; }
        }
        //模拟量元素map
        private Dictionary<int, AnalogEnt> analogEntMap = new Dictionary<int, AnalogEnt>();
        public Dictionary<int, AnalogEnt> AnalogEntMap
        {
            get { return analogEntMap; }
            set { analogEntMap = value; }
        }
        //道岔曲线元素map
        private Dictionary<int, AnalogDCCurve> analogDCCurveEntMap = new Dictionary<int, AnalogDCCurve>();
        public Dictionary<int, AnalogDCCurve> AnalogDCCurveEntMap
        {
            get { return analogDCCurveEntMap; }
            set { analogDCCurveEntMap = value; }
        }
        //其他曲线元素map
        private Dictionary<int, AnalogOtherCurve> analogOtherCurveEntMap = new Dictionary<int, AnalogOtherCurve>();
        public Dictionary<int, AnalogOtherCurve> AnalogOtherCurveEntMap
        {
            get { return analogOtherCurveEntMap; }
            set { analogOtherCurveEntMap = value; }
        }
        //开关量元素map
        private Dictionary<int, DigitEnt> digitEntMap = new Dictionary<int, DigitEnt>();
        public Dictionary<int, DigitEnt> DigitEntMap
        {
            get { return digitEntMap; }
            set { digitEntMap = value; }
        }
        //信号机非正常关闭元素map
        private Dictionary<int, XHJOffAbnormal> xhjOffEntMap = new Dictionary<int, XHJOffAbnormal>();
        public Dictionary<int, XHJOffAbnormal> XhjOffEntMap
        {
            get { return xhjOffEntMap; }
            set { xhjOffEntMap = value; }
        }
        //信号机灯位上下限元素map
        private Dictionary<int, XHJDSDLDwUploadInfo> xhjDSDLDwUploadInfoEntMap = new Dictionary<int, XHJDSDLDwUploadInfo>();
        public Dictionary<int, XHJDSDLDwUploadInfo> XhjDSDLDwUploadInfoEntMap
        {
            get { return xhjDSDLDwUploadInfoEntMap; }
            set { xhjDSDLDwUploadInfoEntMap = value; }
        }
        //晴雨天上下限元素map
        private Dictionary<int, AnalogQYTEnt> analogQYTEntMap = new Dictionary<int, AnalogQYTEnt>();
        public Dictionary<int, AnalogQYTEnt> AnalogQYTEntMap
        {
            get { return analogQYTEntMap; }
            set { analogQYTEntMap = value; }
        }

        /// <summary>
        /// 读取analog.ini文件
        /// </summary>
        /// <param name="file10Path"></param>
        /// <param name="telCode"></param>
        /// <returns></returns>
        public bool ReadAnalog(string file10Path, string telCode)
        {
            bool isRight = false;
            string strChildNum = "";
            //analog存在
            string fileAnalogPath = Path.Combine( file10Path + @"\" + telCode + @"\analog.ini");
            if (!File.Exists(fileAnalogPath))
            {
                return true;
            }
            try
            {
                string childNumStr = "";
                childNumStr = ReadIni.GetProfileString(fileAnalogPath, "模拟量项目", "子项数目", "-1");
                if (childNumStr == "" || childNumStr == "-1")
                {
                    return isRight;
                }
                //检查是否为数字
                if (Regex.IsMatch(childNumStr, "[0-9]+"))
                {
                    int chirdNum = int.Parse(childNumStr);
                    int startID = 1;
                    int startIDCurve = 1;
                    int changeAnalogNum = 0;
                    int changeCurveNum = 0;
                    //获取analog中所有子项的子项类型与序号对应关系
                    for (int i = 1; i <= chirdNum; i++)
                    {
                        string childName = "子项" + i;
                        string childTypeName = ReadIni.GetProfileString(fileAnalogPath, childName, "名称", "");
                        AnalogChildMap.Add(childTypeName, childName);
                    }
                    //Debug.WriteLine(childTypes.Length.ToString());
                    foreach (string strChildType in childTypes)
                    {
                        //Debug.WriteLine(strChildType + " 模拟量起始序号：" + startID + "\t曲线起始序号：" + startIDCurve);
                        //根据类型码读取字段
                        if (AnalogChildMap.ContainsKey(strChildType))
                        {
                            strChildNum = AnalogChildMap[strChildType];
                        }
                        else
                        {
                            continue;
                        }
                        if (strChildType == "全体模拟量")
                        {
                            changeAnalogNum = ReadAnalogEnt(fileAnalogPath, strChildNum, 0, startID);
                            if (changeAnalogNum <= 0)
                            {
                                //出错
                                continue;
                            }
                            else
                            {
                                startID = startID + changeAnalogNum;
                            }
                        }
                        else if (strChildType == "电源漏流")
                        {
                            changeAnalogNum = ReadAnalogEnt(fileAnalogPath, strChildNum, 1, startID);
                            if (changeAnalogNum <= 0)
                            {
                                //出错
                                continue;
                            }
                            else
                            {
                                startID = startID + changeAnalogNum;
                            }
                        }
                        else if (strChildType == "电缆绝缘")
                        {
                            changeAnalogNum = ReadAnalogEnt(fileAnalogPath, strChildNum, 2, startID);
                            if (changeAnalogNum <= 0)
                            {
                                //出错
                                continue;
                            }
                            else
                            {
                                startID = startID + changeAnalogNum;
                            }
                        }
                        else if (strChildType == "道岔启动电流")
                        {
                            changeCurveNum = ReadAnalogEnt(fileAnalogPath, strChildNum, 3, startIDCurve);
                            if (changeCurveNum <= 0)
                            {
                                //出错
                                continue;
                            }
                            else
                            {
                                startIDCurve = startIDCurve + changeCurveNum;
                            }
                        }
                        else if (strChildType == "拉力")
                        {
                            changeCurveNum = ReadAnalogEnt(fileAnalogPath, strChildNum, 4, startIDCurve);
                            if (changeCurveNum <= 0)
                            {
                                //出错
                                continue;
                            }
                            else
                            {
                                startIDCurve = startIDCurve + changeCurveNum;
                            }
                        }
                        else if (strChildType == "油压")
                        {
                            changeCurveNum = ReadAnalogEnt(fileAnalogPath, strChildNum, 5, startIDCurve);
                            if (changeCurveNum <= 0)
                            {
                                //出错
                                continue;
                            }
                            else
                            {
                                startIDCurve = startIDCurve + changeCurveNum;
                            }
                        }
                        else if (strChildType == "高压不对称电压波形")
                        {
                            changeCurveNum = ReadAnalogEnt(fileAnalogPath, strChildNum, 6, startIDCurve);
                            if (changeCurveNum <= 0)
                            {
                                //出错
                                continue;
                            }
                            else
                            {
                                startIDCurve = startIDCurve + changeCurveNum;
                            }
                        }
                        else if (strChildType == "外电网瞬间断电曲线")
                        {
                            changeCurveNum = ReadAnalogEnt(fileAnalogPath, strChildNum, 7, startIDCurve);
                            if (changeCurveNum <= 0)
                            {
                                //出错
                                continue;
                            }
                            else
                            {
                                startIDCurve = startIDCurve + changeCurveNum;
                            }
                        }
                    }
                }
                else
                {
                    return isRight;
                }
                isRight = true;
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }

            return isRight;
        }

        /// <summary>
        /// 读取digit.ini文件
        /// </summary>
        /// <param name="file10Path"></param>
        /// <param name="telCode"></param>
        /// <returns></returns>
        public bool ReadDigit(string file10Path, string telCode)
        {
            bool isRight = false;
            //analog存在
            string fileDigitPath = file10Path + telCode + "/digit.ini";
            if (!File.Exists(fileDigitPath))
            {
                return true;
            }
            try
            {
                string sectionNumStr = "";
                sectionNumStr = ReadIni.GetProfileString(fileDigitPath, "开关量", "总路数", "-1");
                if (sectionNumStr == "-1" || sectionNumStr == "0")
                {
                    return isRight;
                }
                //检查是否为数字
                if (Regex.IsMatch(sectionNumStr, "[0-9]+"))
                {
                    int changeNum = ReadDigitEnt(fileDigitPath, "开关量", 0, 0);
                }
                else
                {
                    return isRight;
                }
                ReadXHJEnt(fileDigitPath, "信号非正常关闭", 0, 0);
                isRight = true;
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }

            return isRight;
        }

        /// <summary>
        /// 读取XHJDSDL.ini文件
        /// </summary>
        /// <param name="file10Path"></param>
        /// <param name="telCode"></param>
        /// <returns></returns>
        public bool ReadXHJDSDL(string file10Path, string telCode)
        {
            bool isRight = false;
            int type = -1;
            //analog存在
            string fileDigitPath = file10Path + telCode + "/XHJDSDL.ini";
            if (!File.Exists(fileDigitPath))
            {
                return true;
            }
            try
            {
                //先读取"信号机灯位设置"
                string sectionDWNumStr = "";
                sectionDWNumStr = ReadIni.GetProfileString(fileDigitPath, "信号机灯位设置", "总路数", "-1");
                if (sectionDWNumStr == "-1" || sectionDWNumStr == "0")
                {
                    return isRight;
                }

                //检查是否为数字
                if (Regex.IsMatch(sectionDWNumStr, "[0-9]+"))
                {
                    type = 0;
                }

                //再次读取"信号机灯位设置"
                string sectionLimitNumStr = "";
                sectionLimitNumStr = ReadIni.GetProfileString(fileDigitPath, "信号机灯位报警上下限设置", "总路数", "-1");
                if (sectionLimitNumStr == "-1" || sectionLimitNumStr == "0")
                {
                    type = 0;
                }
                //
                if (Regex.IsMatch(sectionLimitNumStr, "[0-9]+"))
                {
                    type = 1;
                }
                ReadXHJDSDLEnt(fileDigitPath, "", type, 0);

                isRight = true;
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }

            return isRight;
        }

        /// <summary>
        /// 读取analog_QYT.ini文件
        /// </summary>
        /// <param name="file10Path"></param>
        /// <param name="telCode"></param>
        /// <returns></returns>
        public bool ReadAnalogQYT(string file10Path, string telCode)
        {
            bool isRight = false;
            int type = -1;
            //analog存在
            string fileAnalogQYTPath = file10Path + telCode + "/analog_QYT.ini";
            if (!File.Exists(fileAnalogQYTPath))
            {
                return true;
            }
            try
            {
                string childNumStr = "";
                childNumStr = ReadIni.GetProfileString(fileAnalogQYTPath, "模拟量项目", "子项数目", "null");
                if (childNumStr == "" || childNumStr == "null")
                {
                    return isRight;
                }
                //检查是否为数字
                if (Regex.IsMatch(childNumStr, "[0-9]+"))
                {
                    int chirdNum = int.Parse(childNumStr);
                    string analogQYTChild = "";
                    int analogQYTNum = -1;
                    //获取analog中所有子项的子项类型与序号对应关系
                    for (int i = 1; i <= chirdNum; i++)
                    {
                        string childName = "子项" + i;
                        string childTypeName = ReadIni.GetProfileString(fileAnalogQYTPath, childName, "名称", "null");
                        if (childTypeName == "全体模拟量")
                        {
                            analogQYTChild = childName;
                        }
                    }

                    if (analogQYTChild != "")
                    {
                        analogQYTNum = ReadAnalogQYTEnt(fileAnalogQYTPath, analogQYTChild, 0, 1);
                    }
                }

                isRight = true;
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }

            return isRight;
        }

        /// <summary>
        /// 获取10版格式的数据元
        /// </summary>
        /// <param name="fileAnalogPath"></param>
        /// <param name="childName"></param>
        /// <param name="type"></param>
        /// <param name="stratID"></param>
        /// <returns></returns>
        private int ReadAnalogEnt(string fileAnalogPath, string childName, int type, int stratID)
        {
            int changeNum = 0;
            int beansType = 0;
            int ent18AnalogCFGNum = -1;
            //获取总路数字符串
            string childAnalogNumStr = ReadIni.GetProfileString(fileAnalogPath, childName, "总路数", null);
            //去除注释
            if (childAnalogNumStr.Contains(";"))
            {
                int notesLocal = childAnalogNumStr.IndexOf(";");
                childAnalogNumStr = childAnalogNumStr.Substring(0, notesLocal);
            }
            //判断非null
            if (childAnalogNumStr == null)
            {
                return changeNum;
            }
            //判断为纯数字
            if (Regex.IsMatch(childAnalogNumStr, "[0-9]+"))
            {
                int childAnalogNum = int.Parse(childAnalogNumStr);
                for (int j = 0; j < childAnalogNum; j++)
                {
                    string analogId = (j + 1).ToString();
                    string childAnalogTemp = ReadIni.GetProfileString(fileAnalogPath, childName, analogId, "null");
                    if (childAnalogTemp == "null")
                    {
                        Debug.WriteLine("读取" + childName + "时，未获取到行" + analogId);
                        continue;
                    }
                    //规整数据。，去除空格
                    childAnalogTemp = childAnalogTemp.Replace(" ", "");
                    childAnalogTemp = childAnalogTemp.Replace("\t", "");
                    string[] childAnalogArrayTemp = childAnalogTemp.SplitRemoveEndEmptyEntries(new string[] { "," });
                    if (childAnalogArrayTemp.Length <= 1)
                    {
                        Debug.WriteLine("模拟量行分隔符错误:非英文的逗号");
                        continue;
                    }
                    //数据转储
                    List<string> childAnalogArray = new List<string>();
                    for (int k = 0; k < 39; k++)
                    {
                        if (k >= childAnalogArrayTemp.Length)
                        {
                            childAnalogArray.Add("=-=");
                            continue;
                        }
                        if (k == 15)
                        {
                            if ("" == childAnalogArrayTemp[k])
                            {
                                childAnalogArrayTemp[k] = "0";
                            }
                        }
                        childAnalogArray.Add(childAnalogArrayTemp[k]);
                    }
                    string analogType = "";
                    //普通模拟量
                    if (type == 0)
                    {
                        analogType = childAnalogArray[3];
                        //表示模拟量元素，对应18版的analog的子项1
                        beansType = 1;
                    }
                    //漏流
                    else if (type == 1)
                    {
                        analogType = "3C";
                        //表示模拟量元素，对应18版的analog的子项1
                        beansType = 1;
                    }
                    //绝缘
                    else if (type == 2)
                    {
                        analogType = "3B";
                        //表示模拟量元素，对应18版的analog的子项1
                        beansType = 1;
                    }
                    //道岔电流曲线
                    else if (type == 3)
                    {
                        //表示道岔曲线元素，对应18版的analog的子项2
                        beansType = 2;
                    }
                    //其他曲线,拉力 2
                    else if (type == 4)
                    {
                        //表示其他曲线元素，对应18版的analog的子项2
                        beansType = 3;
                        //18b按配置的曲线类型,拉力 1
                        ent18AnalogCFGNum = 2;
                    }
                    //其他曲线,油压 1
                    else if (type == 5)
                    {
                        //表示其他曲线元素，对应18版的analog的子项2
                        beansType = 3;
                        //18b按配置的曲线类型,油压 2
                        ent18AnalogCFGNum = 1;
                    }
                    //其他曲线,高压不对称波形 3
                    else if (type == 6)
                    {
                        //表示其他曲线元素，对应18版的analog的子项2
                        beansType = 3;
                        //18b按配置的曲线类型,高压不对称波形 3
                        ent18AnalogCFGNum = 3;
                    }
                    //其他曲线,瞬间断电 4
                    else if (type == 7)
                    {
                        //表示其他曲线元素，对应18版的analog的子项2
                        beansType = 3;
                        //18b按配置的曲线类型,瞬间断电 4
                        ent18AnalogCFGNum = 4;
                    }
                    //根据beansType生产10版元素
                    if (beansType == 1)
                    {
                        Debug.WriteLine("GetInit10-模拟量ID：" + stratID);

                        //判断第12列倍率开关是否为整数
                        string num12thStr = childAnalogArray[12];
                        int num12th = 1;
                        bool isNum = Regex.IsMatch(num12thStr, "[0-9]+");
                        if (isNum)
                        {
                            num12th = int.Parse(childAnalogArray[12]);
                        }
                        else
                        {
                            Debug.WriteLine("倍率开关列非整数，请检查！");
                        }

                        //创建模拟量元素
                        AnalogEnt analogEnt = new AnalogEnt(stratID, childAnalogArray[0],
                                int.Parse(childAnalogArray[1]),
                                int.Parse(childAnalogArray[2]),
                                analogType,
                                float.Parse(childAnalogArray[4]),
                                float.Parse(childAnalogArray[5]),
                                float.Parse(childAnalogArray[6]),
                                float.Parse(childAnalogArray[7]),
                                float.Parse(childAnalogArray[8]),
                                float.Parse(childAnalogArray[9]),
                                int.Parse(childAnalogArray[10]),
                                float.Parse(childAnalogArray[11]),
                                num12th,
                                float.Parse(childAnalogArray[13]),
                                float.Parse(childAnalogArray[14]),
                                float.Parse(childAnalogArray[15]),
                                childAnalogArray[16],
                                childAnalogArray[17],
                                childAnalogArray[18],
                                childAnalogArray[19],
                                childAnalogArray[20],
                                childAnalogArray[21],
                                childAnalogArray[22],
                                childAnalogArray[23],
                                childAnalogArray[24],
                                childAnalogArray[25],
                                childAnalogArray[26],
                                childAnalogArray[27],
                                childAnalogArray[28],
                                childAnalogArray[29],
                                childAnalogArray[30],
                                childAnalogArray[31],
                                childAnalogArray[32],
                                childAnalogArray[33],
                                childAnalogArray[34],
                                childAnalogArray[35],
                                childAnalogArray[36],
                                childAnalogArray[37],
                                childAnalogArray[38]
                        );

                        AnalogEntMap.Add(stratID, analogEnt);
                        stratID++;
                        changeNum++;
                        //System.out.println(analogEnt);
                    }
                    else if (beansType == 2)
                    {
                        AnalogDCCurve analogDCCurveTemp = new AnalogDCCurve(
                                stratID,
                                childAnalogArray[0],
                                childAnalogArray[1],
                                childAnalogArray[2],
                                childAnalogArray[3],
                                childAnalogArray[4],
                                childAnalogArray[5],
                                childAnalogArray[6],
                                childAnalogArray[7],
                                childAnalogArray[8],
                                childAnalogArray[9],
                                childAnalogArray[10],
                                childAnalogArray[11],
                                childAnalogArray[12],
                                childAnalogArray[13],
                                childAnalogArray[14],
                                childAnalogArray[15],
                                childAnalogArray[16],
                                childAnalogArray[17],
                                childAnalogArray[18],
                                childAnalogArray[19],
                                childAnalogArray[20],
                                childAnalogArray[21],
                                childAnalogArray[22],
                                childAnalogArray[23],
                                childAnalogArray[24],
                                childAnalogArray[25],
                                childAnalogArray[26],
                                childAnalogArray[27],
                                childAnalogArray[28],
                                childAnalogArray[29],
                                childAnalogArray[30]
                        );
                        AnalogDCCurveEntMap.Add(stratID, analogDCCurveTemp);
                        stratID++;
                        changeNum++;
                    }
                    else if (beansType == 3)
                    {
                        AnalogOtherCurve analogOtherCurve = new AnalogOtherCurve(
                                stratID,
                                ent18AnalogCFGNum,
                                childAnalogArray[0],
                                childAnalogArray[1],
                                childAnalogArray[2],
                                childAnalogArray[3],
                                childAnalogArray[4],
                                childAnalogArray[5],
                                childAnalogArray[6],
                                childAnalogArray[7],
                                childAnalogArray[8],
                                childAnalogArray[9],
                                childAnalogArray[10],
                                childAnalogArray[11],
                                childAnalogArray[12],
                                childAnalogArray[13],
                                childAnalogArray[14],
                                childAnalogArray[15],
                                childAnalogArray[16],
                                childAnalogArray[17],
                                childAnalogArray[18],
                                childAnalogArray[19],
                                childAnalogArray[20]
                        );
                        //System.out.println(analogOtherCurveEntMap);
                        AnalogOtherCurveEntMap.Add(stratID, analogOtherCurve);
                        stratID++;
                        changeNum++;
                    }
                }
            }
            return changeNum;
        }

        /// <summary>
        /// 获取10版格式的开关量数据元
        /// </summary>
        /// <param name="fileDigitPath"></param>
        /// <param name="sectionName"></param>
        /// <param name="type"></param>
        /// <param name="stratID"></param>
        /// <returns></returns>
        private int ReadDigitEnt(string fileDigitPath, string sectionName, int type, int stratID)
        {
            int changeNum = 0;
            //获取总路数字符串
            string childDigitNumStr = ReadIni.GetProfileString(fileDigitPath, sectionName, "总路数", "-1");
            //去除注释
            if (childDigitNumStr.Contains(";"))
            {
                int notesLocal = childDigitNumStr.IndexOf(";");
                childDigitNumStr = childDigitNumStr.Substring(0, notesLocal);
            }
            //判断非null
            if (childDigitNumStr == "-1")
            {
                return changeNum;
            }
            //判断为纯数字
            if (Regex.IsMatch(childDigitNumStr, "[0-9]+"))
            {
                int childDigitNum = int.Parse(childDigitNumStr);
                for (int j = 0; j < childDigitNum; j++)
                {
                    string digitId = (j + 1).ToString();
                    string childDigitTemp = ReadIni.GetProfileString(fileDigitPath, sectionName, digitId, "null");
                    if ("null" == childDigitTemp)
                    {
                        Debug.WriteLine("未获取到开关量行！");
                        continue;
                    }
                    //规整数据。，去除空格
                    childDigitTemp = childDigitTemp.Replace(" ", "");
                    childDigitTemp = childDigitTemp.Replace("\t", "");
                    string[] childDigitArrayTemp = childDigitTemp.SplitRemoveEndEmptyEntries(new string[] { "," });
                    if (childDigitArrayTemp.Length <= 1)
                    {
                        Debug.WriteLine("开关量行分隔符错误:非英文的逗号!");
                        continue;
                    }
                    //数据转储
                    List<string> childDigitArray = new List<string>();
                    for (int k = 0; k < 12; k++)
                    {
                        if (k >= childDigitArrayTemp.Length)
                        {
                            childDigitArray.Add("=-=");
                            continue;
                        }
                        childDigitArray.Add(childDigitArrayTemp[k]);
                    }
                    DigitEnt digitEntTemp = new DigitEnt(
                            digitId,
                            childDigitArray[0],
                            childDigitArray[1],
                            childDigitArray[2],
                            childDigitArray[3],
                            childDigitArray[4],
                            childDigitArray[5],
                            childDigitArray[6],
                            childDigitArray[7],
                            childDigitArray[8],
                            childDigitArray[9],
                            childDigitArray[10]
                    );
                    DigitEntMap.Add(stratID, digitEntTemp);
                    stratID++;
                    changeNum++;
                }
            }
            return changeNum;
        }

        /// <summary>
        /// 获取10版格式的信号机数据元
        /// </summary>
        /// <param name="fileDigitPath"></param>
        /// <param name="sectionName"></param>
        /// <param name="type"></param>
        /// <param name="stratID"></param>
        /// <returns></returns>
        private int ReadXHJEnt(string fileDigitPath, string sectionName, int type, int stratID)
        {
            int changeNum = 0;
            //获取总路数字符串
            string childXHJNumStr = ReadIni.GetProfileString(fileDigitPath, sectionName, "总路数", "-1");
            //去除注释
            if (childXHJNumStr.Contains(";"))
            {
                int notesLocal = childXHJNumStr.IndexOf(";");
                childXHJNumStr = childXHJNumStr.Substring(0, notesLocal);
            }
            //判断非null
            if (childXHJNumStr == "-1")
            {
                return changeNum;
            }
            //判断为纯数字
            if (Regex.IsMatch(childXHJNumStr, "[0-9]+"))
            {
                int childXHJNum = int.Parse(childXHJNumStr);
                for (int j = 0; j < childXHJNum; j++)
                {
                    string xhjId = (j + 1).ToString();
                    string childXHJTemp = ReadIni.GetProfileString(fileDigitPath, sectionName, xhjId, null);
                    if (childXHJTemp == null)
                    {
                        Debug.WriteLine("未获取到开关量行！");
                        continue;
                    }

                    XHJOffAbnormal xhjEntTemp = new XHJOffAbnormal(
                            xhjId,
                            childXHJTemp
                    );
                    XhjOffEntMap.Add(stratID, xhjEntTemp);
                    stratID++;
                    changeNum++;
                }
            }
            return changeNum;
        }

        /// <summary>
        /// 获取10版格式的信号机灯位以及灯丝电流上下限数据元
        /// </summary>
        /// <param name="fileDigitPath"></param>
        /// <param name="sectionName"></param>
        /// <param name="type"></param>
        /// <param name="stratID"></param>
        /// <returns></returns>
        private int ReadXHJDSDLEnt(string fileDigitPath, string sectionName, int type, int stratID)
        {
            int changeNum = 0;
            Dictionary<string, List<DWLimit>> childXHJDWLimitMap = new Dictionary<string, List<DWLimit>>();
            //判断type是否为1
            if (type == 1)
            {
                //获取总路数字符串
                string childXHJDWLimitNumStr = ReadIni.GetProfileString(fileDigitPath, "信号机灯位报警上下限设置", "总路数", "-1");
                //去除注释
                if (childXHJDWLimitNumStr.Contains(";"))
                {
                    int notesLocal = childXHJDWLimitNumStr.IndexOf(";");
                    childXHJDWLimitNumStr = childXHJDWLimitNumStr.Substring(0, notesLocal);
                }
                //判断非null
                if (childXHJDWLimitNumStr != "-1")
                {
                    int childXHJDWLimitNum = int.Parse(childXHJDWLimitNumStr);
                    for (int j = 0; j < childXHJDWLimitNum; j++)
                    {
                        string xhjId = (j + 1).ToString();
                        string childXHJDWLimitTemp = ReadIni.GetProfileString(fileDigitPath, "信号机灯位报警上下限设置", xhjId, null);
                        if (childXHJDWLimitTemp == null)
                        {
                            Debug.WriteLine("未获取到XHJDSDLDWLimit行！");
                            continue;
                        }
                        //规整数据
                        childXHJDWLimitTemp = childXHJDWLimitTemp.Trim();
                        childXHJDWLimitTemp = childXHJDWLimitTemp.Replace("\t", "");
                        childXHJDWLimitTemp = childXHJDWLimitTemp.Replace(" ", "");
                        string[] childXHJDWTempList = childXHJDWLimitTemp.SplitRemoveEndEmptyEntries(new string[] { "," });

                        //准备数据
                        List<DWLimit> xhjLimitUpperLower = new List<DWLimit>();
                        if (childXHJDWTempList.Length == 0)
                        {
                            continue;
                        }
                        if (childXHJDWTempList[1] == "-1")
                        {
                            continue;
                        }

                        //查找信号机灯位信息
                        for (int i = 0; i < 15; i++)
                        {
                            DWLimit dwLimitTemp = new DWLimit();
                            if (i * 2 >= (childXHJDWTempList.Length - 2))
                            {
                                dwLimitTemp.XhjDWName = XHJDWNumToName.ChangeXHJDWNumToName(i + 1);
                                dwLimitTemp.XhjLimitLower = "-1";
                                dwLimitTemp.XhjLimitUpper = "-1";
                            }
                            else
                            {
                                dwLimitTemp.XhjDWName = XHJDWNumToName.ChangeXHJDWNumToName(i + 1);
                                dwLimitTemp.XhjLimitLower = childXHJDWTempList[2 + i * 2];
                                dwLimitTemp.XhjLimitUpper = childXHJDWTempList[3 + i * 2];
                            }
                            xhjLimitUpperLower.Add(dwLimitTemp);
                        }
                        childXHJDWLimitMap.Add(childXHJDWTempList[0], xhjLimitUpperLower);
                    }
                }
            }

            //开始处理灯位，获取总路数字符串
            string childXHJDWNumStr = ReadIni.GetProfileString(fileDigitPath, "信号机灯位设置", "总路数", "-1");
            //去除注释
            if (childXHJDWNumStr.Contains(";"))
            {
                int notesLocal = childXHJDWNumStr.IndexOf(";");
                childXHJDWNumStr = childXHJDWNumStr.Substring(0, notesLocal);
            }
            //判断非null
            if (childXHJDWNumStr == "-1")
            {
                return changeNum;
            }
            //判断为纯数字
            if (Regex.IsMatch(childXHJDWNumStr, "[0-9]+"))
            {
                int childXHJDWNum = int.Parse(childXHJDWNumStr);
                for (int j = 0; j < childXHJDWNum; j++)
                {
                    string xhjId = (j + 1).ToString();
                    string childXHJDWTemp = ReadIni.GetProfileString(fileDigitPath, "信号机灯位设置", xhjId, "null");
                    if ("null" == childXHJDWTemp)
                    {
                        Debug.WriteLine("未获取到XHJDSDL行！");
                        continue;
                    }
                    //规整数据
                    childXHJDWTemp = childXHJDWTemp.Trim();
                    childXHJDWTemp = childXHJDWTemp.Replace("\t", "");
                    childXHJDWTemp = childXHJDWTemp.Replace(" ", "");
                    string[] childXHJDWTempList = childXHJDWTemp.SplitRemoveEndEmptyEntries(new string[] { "," });
                    //准备数据
                    List<DWLimit> xhjLimitUpperLower = new List<DWLimit>();
                    List<DWInfo> xhjDWInfo = new List<DWInfo>();
                    if (childXHJDWTempList.Length == 0)
                    {
                        continue;
                    }
                    if (childXHJDWTempList[1] == "-1")
                    {
                        continue;
                    }
                    XHJDSDLDwUploadInfo xhjdsdlDwUploadInfo = new XHJDSDLDwUploadInfo(j + 1, childXHJDWTempList[0], childXHJDWTempList[1]);
                    //查找信号机灯位信息
                    for (int i = 0; i < 15; i++)
                    {
                        DWInfo dwInfoTemp = new DWInfo();
                        if (i >= childXHJDWTempList.Length)
                        {
                            dwInfoTemp.XhjDWName = XHJDWNumToName.ChangeXHJDWNumToName(i + 1);
                            dwInfoTemp.XhjDWInfo = "-1";
                        }
                        else
                        {
                            dwInfoTemp.XhjDWName = XHJDWNumToName.ChangeXHJDWNumToName(i + 1);
                            dwInfoTemp.XhjDWInfo = childXHJDWTempList[i + 2];
                        }
                        xhjDWInfo.Add(dwInfoTemp);
                    }
                    xhjdsdlDwUploadInfo.XhjDWInfo = xhjDWInfo;
                    if (type == 1)
                    {
                        if (childXHJDWLimitMap.ContainsKey(xhjdsdlDwUploadInfo.XhjName))
                        {
                            xhjdsdlDwUploadInfo.XhjLimitUpperLower = childXHJDWLimitMap[xhjdsdlDwUploadInfo.XhjName];
                        }

                    }
                    XhjDSDLDwUploadInfoEntMap.Add(j, xhjdsdlDwUploadInfo);

                    stratID++;
                    changeNum++;
                }

            }
            return changeNum;
        }

        /// <summary>
        /// 获取10版格式的晴雨天数据元
        /// </summary>
        /// <param name="fileAnalogQYTPath"></param>
        /// <param name="childName"></param>
        /// <param name="type"></param>
        /// <param name="stratID"></param>
        /// <returns></returns>
        private int ReadAnalogQYTEnt(string fileAnalogQYTPath, string childName, int type, int stratID)
        {
            int changeNum = 0;
            //获取总路数字符串
            string childAnalogQYTNumStr = ReadIni.GetProfileString(fileAnalogQYTPath, childName, "总路数", "-1");
            //去除注释
            if (childAnalogQYTNumStr.Contains(";"))
            {
                int notesLocal = childAnalogQYTNumStr.IndexOf(";");
                childAnalogQYTNumStr = childAnalogQYTNumStr.Substring(0, notesLocal);
            }
            //判断非null
            if (childAnalogQYTNumStr == "-1")
            {
                return changeNum;
            }
            //判断为纯数字
            if (Regex.IsMatch(childAnalogQYTNumStr, "[0-9]+"))
            {
                int childAnalogNum = int.Parse(childAnalogQYTNumStr);
                for (int j = 0; j < childAnalogNum; j++)
                {
                    string analogId = (j + 1).ToString();
                    string childAnalogTemp = ReadIni.GetProfileString(fileAnalogQYTPath, childName, analogId, "null");
                    if (childAnalogTemp == "null")
                    {
                        Debug.WriteLine("读取晴雨天时，未获取到模拟量行" + analogId);
                        continue;
                    }
                    //规整数据。，去除空格
                    childAnalogTemp = childAnalogTemp.Replace(" ", "");
                    childAnalogTemp = childAnalogTemp.Replace("\t", "");
                    string[] childAnalogArrayQYTTemp = childAnalogTemp.SplitRemoveEndEmptyEntries(new string[] { "," });
                    if (childAnalogArrayQYTTemp.Length <= 1)
                    {
                        Debug.WriteLine("模拟量行分隔符错误:非英文的逗号");
                        continue;
                    }
                    //数据转储
                    List<string> childAnalogQYTArray = new List<string>();
                    for (int k = 0; k < 10; k++)
                    {
                        if (k >= childAnalogArrayQYTTemp.Length)
                        {
                            childAnalogQYTArray.Add("=-=");
                            continue;
                        }
                        childAnalogQYTArray.Add(childAnalogArrayQYTTemp[k]);
                    }
                    if (Convert.ToInt32(childAnalogQYTArray[2], 16) == 29 || Convert.ToInt32(childAnalogQYTArray[2], 16) == 22)
                    {
                        AnalogQYTEnt analogQYTEnt = new AnalogQYTEnt(stratID,
                                childAnalogQYTArray[0],
                                childAnalogQYTArray[1],
                                childAnalogQYTArray[2],
                                childAnalogQYTArray[3],
                                childAnalogQYTArray[4],
                                childAnalogQYTArray[5],
                                childAnalogQYTArray[6],
                                childAnalogQYTArray[7],
                                childAnalogQYTArray[8],
                                childAnalogQYTArray[9]);
                        AnalogQYTEntMap.Add(stratID, analogQYTEnt);
                        stratID++;
                        changeNum++;
                    }
                }
            }
            return changeNum;
        }
    }
}
